package com.lft.com.oilgas.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lft.com.oilgas.entity.Merchant;
import com.lft.com.oilgas.mapper.MerchantMapper;
import com.lft.com.oilgas.service.IMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author tyqw
 * @since 2024-09-10
 */
@Service
@Transactional
public class MerchantServiceImpl implements IMerchantService {

    @Autowired(required = false)
    private MerchantMapper merchantMapper;

    @Override
    public Merchant selectByid(Integer id) {
        return  merchantMapper.selectById(id);
    }

    @Override
    public List<Map<String, Object>> getAllMerchantsWithLegalPersonName(Map map) {
        int pageNo = (Integer) map.get("pageNo");
        int pageSize = (Integer) map.get("pageSize");
        int offset = (pageNo - 1) * pageSize;
        if (map.get("contacts") != null && map.get("contacts") != null) {
            String contacts = map.get("contacts").toString();
            map.put("tiaojian", contacts);
        } else {
            map.put("tiaojian", "");
        }
        map.put("offset", offset);
        map.put("row_count", pageSize);
        return  merchantMapper.selectAllMerchantsWithLegalPersonName(map);
    }

    @Override
    public int insertOrUpdateMerchant(Merchant merchant) {
        System.out.println(merchant);
        if (merchant.getId() == null) {
            return merchantMapper.insert(merchant);
        } else {
            return merchantMapper.updateById(merchant);
        }
    }

    @Override
    public Merchant selectOne(Integer id) {
        LambdaQueryWrapper<Merchant> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(Merchant::getUserId,id);
        return  merchantMapper.selectOne(queryWrapper);
    }

    @Override
    public int updateByidzz(Integer id, String a) {
        Merchant merchant = merchantMapper.selectById(id);
        merchant.setOtherQualifications(a);
        return  merchantMapper.updateById(merchant);
    }

}
